﻿<!-- 正文开始 -->
<style >
    #tableIcon + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIcon + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: auto;
        line-height: 30px;
        padding: 0 5px;
    }

    .tdImg {
        width: 35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    } 
</style>

<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button type="button" class="layui-btn" id="uploadPictureBtn"><i class="layui-icon">&#xe67c;</i>上传图标</button>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">场景</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入场景名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchPicture" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>

			<table class="layui-table" id="tablePicture" lay-filter="tablePicture"></table>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarPicture">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="addImgHtml">
<div class="layui-card" style="box-shadow: none;">
    <div class="layui-card-body" style="padding: 5px;">
<div class="layui-upload">
  <button type="button" class="layui-btn" id="test1">上传图片</button>
  <div class="layui-upload-list">
    <img class="layui-upload-img" id="demo1">
    <p id="demoText"></p>
  </div>
</div>  

    </div>
</div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin','upload','zTree'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var upload = layui.upload;
        // 渲染表格
        var insTb = table.render({
            elem: '#tablePicture',
            url: '#(ctx)/biz/picture/listData',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {
                    align: 'center', templet: function (d) {
                    	if(d.url)
                        	return '<img src="#(ctx)'+d.url+'" class="tdImg" />';
                        else
                        	return '';
                    }, title: '缩略图', width: 100, unresize: true
                },
                {field: 'name', sort: false, title: '名称'},
                {field: 'width', sort: false, title: '宽度'},
                {field: 'height', sort: false, title: '高度'},
                {align: 'center', toolbar: '#tableBarPicture', title: '操作', minWidth: 200}
            ]]
        });


        // 搜索
        form.on('submit(formSubSearchPicture)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tablePicture)', function (obj) {	
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') { // 删除
                doDel(obj);
            }
        });
        
       upload.render({
          elem: '#uploadPictureBtn'
          ,url: '#(ctx)/biz/picture/upload'
          ,accept: 'images'
       	  ,before: function(obj){ 
    	    layer.load(); 
    	  }
    	  ,done: function(res, index, upload){
    		layer.closeAll('loading'); //关闭loading
            if (200==res.code) {
                layer.msg(res.message, {icon: 1});
                insTb.reload();
            } else {
                layer.msg(res.message, {icon: 2});
            }
    	  }
    	  ,error: function(index, upload){
    	    layer.closeAll('loading');
    	    layer.msg("上传失败！", {icon: 2});
    	  }       
        });

        // 删除
        function doDel(obj) {
            layer.confirm('确定要删除“【<span style="color:red;">' + obj.data.name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/picture/delete', {
                    id: obj.data.id
                }, function (res) {
                    layer.closeAll('loading');
                    if (200==res.code) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload();
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }
    });
</script>